using UnityEngine;
using System.Collections;

public class ScoreManager : MonoBehaviour 
{
	public int score = 0;
	
	public double timeForMeter;
	public double boostTimeForMeter;
	private double originalTimeForMeter;
	
	private float cronometer;

	public string scoreTag;
    private CatManager catManager;
	
	void Start () 
	{
        catManager = GameObject.FindGameObjectWithTag(Tags.CAT_MANAGER).GetComponent<CatManager>();
		this.originalTimeForMeter = timeForMeter;
	}
	
	void Update ()
	{
		if(this.score < 10){
			GetComponent<TextMesh>().text = ("0" + score );
		}else
		{
			GetComponent<TextMesh>().text = ("" + score );
		}

        if(gameObject.tag == Tags.SCORE_DISTANCE)
        {
            if(score == 50)
            {
                catManager.ChangeDificult(Dificult.Level2);
                Debug.Log("Level 2");
            }

            if(score == 100)
            {
                catManager.ChangeDificult(Dificult.Level3);
                Debug.Log("Level 3");
            }

            if(score == 150)
            {
                catManager.ChangeDificult(Dificult.Level4);
                Debug.Log("Level 4");
            }

            if(score == 250)
            {
                catManager.ChangeDificult(Dificult.Level5);
                Debug.Log("Level 5");
            }
        }
	}
	
	public int AddScore()
	{
		if(tag == gameObject.tag)
		{
			score ++;
		}
		
		return score;
	}
	
	public void AddScore_Continuous()
	{
		if(tag == gameObject.tag)
		{
			this.cronometer += Time.deltaTime;
			
				if(PlayerMechanic.gameVel != 1)
				{
					this.timeForMeter = boostTimeForMeter;
					
				}else
			{
				this.timeForMeter = originalTimeForMeter;
			}
			
			if(this.cronometer >= timeForMeter){
				
				score++;
				
				this.cronometer = 0;
			}
		}
	}
	
	public int GetScore()
	{
		return score;
	}
}
